package org.credo.net.study;

import java.io.IOException;
import java.net.InetAddress;

public class InetAddressTest {

	public static void main(String[] args) throws IOException {
		//根据主机名来获取对应的InetAddress实例
		InetAddress ip=InetAddress.getByName("www.oschina.net");
		//判断是否可以到达
		System.out.println("是否可以到达OSC:"+ip.isReachable(2000));
		//获取该InetAddress实例的IP字符串
		System.out.println(ip.getHostAddress());
		//根据原始IP地址来获取对应的InetAddress实例
		InetAddress local=InetAddress.getByAddress(new byte[]{127,0,0,1});
		//InetAddress local=InetAddress.getLocalHost();
		System.out.println("本机是否可以到达:"+local.isReachable(5000));
		//获取该InetAddress实例对应的全限定域名
		System.out.println(local.getCanonicalHostName());
		System.out.println(local.getHostAddress());
	}

}
